package com.symc.sims0213xfw.controller.student;

import com.symc.sims0213xfw.service.OperationStatusResult;
import com.symc.sims0213xfw.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: 凤文  沈阳医学院2019级医学信息工程 0213
 * @CreateTime: 2022/01/22 23:03
 * @Description:
 */
@WebServlet("/deleteStudentServlet")
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        Long status = new StudentServiceImpl().deleteStudent(id);
        PrintWriter out = response.getWriter();
        if (status == OperationStatusResult.SUCCESS) {
            out.write("删除成功！");
        } else if (status == OperationStatusResult.NOT_EXIST) {
            out.write("该学生不存在！");
        } else if (status == OperationStatusResult.DEFEAT) {
            out.write("删除失败！");
        }
        out.write("<br>2秒后自动跳转到查看页面。。。");
        response.setHeader("refresh", "2,url=/SMIS0213xfw//listStudentViewServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
